package com.revai.engine;

import org.mybatis.generator.api.IntrospectedColumn;
import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;
import org.mybatis.generator.internal.types.JavaTypeResolverDefaultImpl;

public class CodeJavaTypeResolver extends JavaTypeResolverDefaultImpl {
    /**
     * 解决 数据库 Text 类型生成实体， 优化 查询，会生成xxxWithBLOBs 问题
     */
    @Override
    public FullyQualifiedJavaType calculateJavaType(IntrospectedColumn introspectedColumn) {
        FullyQualifiedJavaType answer = null;
        JdbcTypeInformation jdbcTypeInformation = null;
        // 如果是Text 转换为 varChar 其它相同类型也会受影响
        if (introspectedColumn.getJdbcType() == -1) {
            introspectedColumn.setJdbcType(12);
            jdbcTypeInformation = typeMap.get(12);
        } else
            jdbcTypeInformation = typeMap.get(introspectedColumn.getJdbcType());
        if (jdbcTypeInformation != null) {
            answer = jdbcTypeInformation.getFullyQualifiedJavaType();
            answer = overrideDefaultType(introspectedColumn, answer);
        }
        return answer;
    }
}